Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
"unexpected end of input" when Jinja templating used to provide multiple parameters to onclick function

I'm trying to run a js function using parameters passed into the template via jinja, where item contains strings as follows:

item.id = 'item1'
item.indicator = 'yes' #or no

Template code:

{% for item in items %}
        <!--The error is thrown by the line directly below!-->
        <div class='qitem' id='{{item.id}}' onclick = change_background('{{item.indicator}}', '{{item.id}}')></div>
{% endfor %}

<script>
function change_background(indicator, id){
    if (indicator == 'yes'){
        document.getElementById(id).style.background='lightgreen';
    }else{
        document.getElementById(id).style.background='pink';
</script>

In the culpable line in my code, '{{item.indicator}}' is red, and the first ' is underlined in vscode.

The code works despite this, if only ONE argument it used as follows: change_background('{{item.indicator}}') (with corresponding function adjusted accordingly), but does not work if I try to use two arguments.

The order of the arguments doesn't seem to matter. Neither does using "{{}}" instead of '{{}}'.

Additionally, if I attempt to run two functions onclick: <div class='qitem' id='{{item.id}}' onclick = make_green('{{item.id}}'); increment_click('{{item.indicator}}')>

only the first executes, and the second is ignored without any errors being thrown!

I've searched on here and elsewhere. I don't really want to jsonify the data I pass in to the template. I feel as though there's a nuance I'm missing when using jinja.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The nuance here is simply your use of JavaScript in HTML.

You'll need

onclick="change_background('{{item.indicator}}', '{{item.id}}')"

instead of

onclick = change_background('{{item.indicator}}', '{{item.id}}')>

to properly wrap the JavaScript segment in quotes.

Additionally, if I attempt to run two functions onclick:

<div class='qitem' id='{{item.id}}' onclick = > make_green('{{item.id}}'); increment_click('{{item.indicator}}')>

Same thing here.

onclick="make_green('{{item.id}}');increment_click('{{item.indicator}}')"
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda